package cn.cmeizu.spring6.jdbc.xmltx.dao.impl;

import cn.cmeizu.spring6.jdbc.xmltx.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author cmeizu
 * @date 2023/2/12 23:01
 */
@Repository
public class BookDaoImpl implements BookDao {
  @Autowired
  private JdbcTemplate jdbcTemplate;

  @Override
  public Long getPriceByBookId(Integer bookId) {
    String sql = "select price from t_book where book_id = ?";
    return jdbcTemplate.queryForObject(sql, Long.class, bookId);
  }

  @Override
  public void updateStock(Integer bookId) {
    String sql = "update t_book set stock = stock-1 where book_id = ?";
    jdbcTemplate.update(sql, bookId);
  }
}
